*&---------------------------------------------------------------------*
*& Report ZEX_LISTING_224                                              *
*&---------------------------------------------------------------------*
*& Created By: James Wood (james.wood@bowdarkconsulting.com)           *
*& Created On: 12/12/2008                                              *
*& Purpose:    This program contains the source code from the regular  *
*&             expressions demo shown in Listing 2.24.                 *
*&---------------------------------------------------------------------*
REPORT zex_listing_224.

*&---------------------------------------------------------------------*
*& Selection Screen Definition                                         *
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK blk_main.
PARAMETERS:
  p_phone TYPE ad_tlnmbr1.
SELECTION-SCREEN END OF BLOCK blk_main.

*&---------------------------------------------------------------------*
*& AT SELECTION-SCREEN Event                                           *
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN ON p_phone.
  PERFORM check_phone_number.

*&---------------------------------------------------------------------*
*& START-OF-SELECTION Event                                            *
*&---------------------------------------------------------------------*
START-OF-SELECTION.
  WRITE: / 'You entered: ', p_phone.

*&---------------------------------------------------------------------*
*&      Form  check_phone_number
*&---------------------------------------------------------------------*
FORM check_phone_number.

* Local Data Declarations:
  DATA: lr_regex   TYPE REF TO cl_abap_regex,
        lr_matcher TYPE REF TO cl_abap_matcher.

* Create the regular expression:
  CREATE OBJECT lr_regex
    EXPORTING
      pattern = '\(\d{3}\)\d{3}-\d{4}'.

* Check to see if the phone number matches the
* regular expression:
  CREATE OBJECT lr_matcher
    EXPORTING
      regex = lr_regex
      text  = p_phone.

  IF lr_matcher->match( ) NE abap_true.
    MESSAGE 'Enter phone number in (xxx)xxx-xxxx format.'
       TYPE 'E'.
  ENDIF.

ENDFORM.                    "check_phone_number